package com_10;

import com_9.SocketThread;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ServerTCP {//定义一个服务端

    public static void main(String[] args) throws IOException {
        //main方法入口
        ServerSocket ss = new ServerSocket(10086);
        ///创建服务端对象
        while (true) {
            Socket sk = ss.accept();
            ExecutorService es = Executors.newFixedThreadPool(10);
            es.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        BufferedReader br = new BufferedReader(new InputStreamReader(sk.getInputStream()));
                        int count = 0;
                        File f = new File("UDP\\x.[" + count + "]text");
                        while (f.exists()) {//
                            count++;//
                            f = new File("UDP\\x.[" + count + "]text");//
                        }
                        BufferedWriter bw = new BufferedWriter(new FileWriter(f));//
                        String line;//
                        while ((line = br.readLine()) != null) {//
                            bw.write(line);//
                            bw.newLine();//
                            bw.flush();//
                        }
                        br.close();//
                        bw.close();//
                    } catch (IOException e) {//
                        e.printStackTrace();//
                    }
                }
            });
        }

    }
}





